package com.peas.platform.module.icims.budget.adjust.api;

import cn.hutool.core.util.StrUtil;
import com.peas.platform.common.core.dto.ResponseDto;
import com.peas.platform.module.icims.budget.adjust.api.req.SaveBudgetNewVo;
import com.peas.platform.module.icims.budget.adjust.api.req.SubmitBudgetNewVo;
import com.peas.platform.module.icims.budget.adjust.dto.BudgetNewDto;
import com.peas.platform.module.icims.budget.adjust.service.BudgetNewService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.ArrayList;
import java.util.List;

@Api(tags = "自定义接口-[预算控制]年中新预算")
@RestController
@RequestMapping("/api/v1/customBudgetNew")
public class CustomBudgetNewApiController {

    @Resource
    private BudgetNewService budgetNewService;

    @ApiOperation(value = "编辑暂存年中新预算")
    @PostMapping("/stageBudgetNew")
    public ResponseDto<BudgetNewDto> stageBudgetNew(@RequestBody @Valid SaveBudgetNewVo vo) {
        BudgetNewDto dto = budgetNewService.saveBudgetNew(vo);
        return ResponseDto.getSuccessResponseDto(dto);
    }

    @ApiOperation(value = "编辑保存年中新预算")
    @PostMapping("/saveBudgetNew")
    public ResponseDto<Boolean> saveBudgetNew(@RequestBody @Valid SaveBudgetNewVo vo) {
        budgetNewService.saveBudgetNew(vo);
        return ResponseDto.getSuccessResponseDto(true);
    }

    @ApiOperation(value = "编辑提交年中新预算")
    @PostMapping("/submitBudgetNew")
    public ResponseDto<Boolean> submitBudgetNew(@RequestBody @Valid SubmitBudgetNewVo vo) {
        budgetNewService.submitBudgetNew(vo);
        return ResponseDto.getSuccessResponseDto(true);
    }

    @ApiOperation(value = "撤回年中新预算")
    @PostMapping("/revocationBudgetNew/{id}")
    public ResponseDto<Boolean> revocationBudgetNew(@PathVariable("id") Long id) {
        budgetNewService.revocationBudgetNew(id);
        return ResponseDto.getSuccessResponseDto(true);
    }

    @ApiOperation(value = "根据ID查询年中新预算，包含统计金额")
    @GetMapping("/queryBudgetNewByIds/{ids}")
    public ResponseDto<List<BudgetNewDto>> queryBudgetNewByIds(@PathVariable(value = "ids") String ids) {
        List<Long> idList = new ArrayList<>();
        for (String id : StrUtil.split(ids, StrUtil.COMMA)) {
            idList.add(Long.valueOf(id));
        }
        List<BudgetNewDto> list = budgetNewService.queryBudgetNewById(idList);
        return ResponseDto.getSuccessResponseDto(list);
    }

    @ApiOperation(value = "根据一级项目ID查询年中新预算，包含统计金额")
    @GetMapping("/queryBudgetNewByProjectOneId/{id}")
    public ResponseDto<List<BudgetNewDto>> queryBudgetNewByProjectOneId(@PathVariable(value = "id") Long id) {
        List<BudgetNewDto> list = budgetNewService.queryBudgetNewByProjectOneId(id);
        return ResponseDto.getSuccessResponseDto(list);
    }

    @ApiOperation(value = "根据组织架构ID查询年中新预算，包含统计金额")
    @GetMapping("/queryBudgetNewByOrganizationId/{id}")
    public ResponseDto<List<BudgetNewDto>> queryBudgetNewByOrganizationId(@PathVariable(value = "id") Long id) {
        List<BudgetNewDto> list = budgetNewService.queryBudgetNewByOrganizationId(id);
        return ResponseDto.getSuccessResponseDto(list);
    }

    @ApiOperation(value = "根据申报单位ID查询年中新预算，包含统计金额")
    @GetMapping("/queryBudgetNewByApplyGovernmentId/{id}")
    public ResponseDto<List<BudgetNewDto>> queryBudgetNewByApplyGovernmentId(@PathVariable(value = "id") Long id) {
        List<BudgetNewDto> list = budgetNewService.queryBudgetNewByApplyGovernmentId(id);
        return ResponseDto.getSuccessResponseDto(list);
    }

    @ApiOperation(value = "根据用款单位ID查询年中新预算，包含统计金额")
    @GetMapping("/queryBudgetNewByUseGovernmentId/{id}")
    public ResponseDto<List<BudgetNewDto>> queryBudgetNewByUseGovernmentId(@PathVariable(value = "id") Long id) {
        List<BudgetNewDto> list = budgetNewService.queryBudgetNewByUseGovernmentId(id);
        return ResponseDto.getSuccessResponseDto(list);
    }

}
